package com.yd.app.mapper.provider;


import com.yd.domain.searchParam.GoodsSearchParam;
import org.springframework.util.StringUtils;

import java.util.Map;

/**
 * Created by zg
 */

public class GoodsProvider extends BaseProvider{


    //查询商品信息list
    public String getGoodsList(Map map){
        GoodsSearchParam searchParam = (GoodsSearchParam)map.get("model");
        StringBuffer buffer = new StringBuffer();
        buffer.append("select business_goods.*,type.typeName,style.typeName gstyleName,o.title as typeOneName,p.title as pxName, " +
                " case business_goods.checkStatus when '0' then '未审核' when '1' then '审核通过' else '审核不通过' end as checkStatusName" +
                " FROM business_goods left join business_gtype type on business_goods.type=type.id " +
                " left join business_gstyle style on business_goods.gstyle=style.id" +
                " left join business_gtype_one o on o.id=business_goods.typeOne " +
                " LEFT JOIN business_pinxing p on business_goods.px=p.id ");
        //添加条件
        buffer.append(this.buildSearchUserSqlConditions(searchParam));
        addFenyeSql(buffer);
        return buffer.toString();
    }
    ///查询商品信息list  Count
    public String getGoodsListCount(Map map){
        GoodsSearchParam searchParam = (GoodsSearchParam)map.get("model");
        StringBuffer buffer = new StringBuffer();
        buffer.append("select count(business_goods.id) FROM business_goods ");
        //添加条件
        buffer.append(this.buildSearchUserSqlConditions(searchParam));
        return buffer.toString();
    }
    private String buildSearchUserSqlConditions(GoodsSearchParam param){
        StringBuilder buffer = new StringBuilder(" where 1=1");
        if(!StringUtils.isEmpty(param.getTitle())){
            buffer.append(" AND business_goods.title like '%"+param.getTitle()+"%'");
        }
        if(!StringUtils.isEmpty(param.getStatus())){
            buffer.append(" and business_goods.status = '"+param.getStatus()+"'  ");
        }
        if(!StringUtils.isEmpty(param.getCheckStatus())){
            buffer.append(" and business_goods.checkStatus = '"+param.getCheckStatus()+"'  ");
        }
        if(!StringUtils.isEmpty(param.getTypeOne())){
            buffer.append(" and business_goods.typeOne = '"+param.getTypeOne()+"'  ");
        }
        if(!StringUtils.isEmpty(param.getType())){
            buffer.append(" and business_goods.type = '"+param.getType()+"'  ");
        }
        if(!StringUtils.isEmpty(param.getGstyle())){
            buffer.append(" and business_goods.gstyle = '"+param.getGstyle()+"'  ");
        }
        if(!StringUtils.isEmpty(param.getPx())){
            buffer.append(" and business_goods.px = '"+param.getPx()+"'  ");
        }
        buffer.append(" order by createTime desc ");
        return buffer.toString();
    }
}
